{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 31省市居民家庭消费调查（K-Means）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "city=pd.read_csv('./city.txt',encoding='gbk',header=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array(['北京', '天津', '河北', '山西', '内蒙古', '辽宁', '吉林', '黑龙江', '上海', '江苏', '浙江',\n       '安徽', '福建', '江西', '山东', '河南', '湖南', '湖北', '广东', '广西', '海南', '重庆',\n       '四川', '贵州', '云南', '西藏', '陕西', '甘肃', '青海', '宁夏', '新疆'], dtype=object)"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "cityName=city.iloc[:,0].values\n",
    "cityName"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "          1       2       3       4       5        6        7       8\n0   2959.19  730.79  749.41  513.34  467.87  1141.82   478.42  457.64\n1   2459.77  495.47  697.33  302.87  284.19   735.97   570.84  305.08\n2   1495.63  515.90  362.37  285.32  272.95   540.58   364.91  188.63\n3   1406.33  477.77  290.15  208.57  201.50   414.72   281.84  212.10\n4   1303.97  524.29  254.83  192.17  249.81   463.09   287.87  192.96\n5   1730.84  553.90  246.91  279.81  239.18   445.20   330.24  163.86\n6   1561.86  492.42  200.49  218.36  220.69   459.62   360.48  147.76\n7   1410.11  510.71  211.88  277.11  224.65   376.82   317.61  152.85\n8   3712.31  550.74  893.37  346.93  527.00  1034.98   720.33  462.03\n9   2207.58  449.37  572.40  211.92  302.09   585.23   429.77  252.54\n10  2629.16  557.32  689.73  435.69  514.66   795.87   575.76  323.36\n11  1844.78  430.29  271.28  126.33  250.56   513.18   314.00  151.39\n12  2709.46  428.11  334.12  160.77  405.14   461.67   535.13  232.29\n13  1563.78  303.65  233.81  107.90  209.70   393.99   509.39  160.12\n14  1675.75  613.32  550.71  219.79  272.59   599.43   371.62  211.84\n15  1427.65  431.79  288.55  208.14  217.00   337.76   421.31  165.32\n16  1942.23  512.27  401.39  206.06  321.29   697.22   492.60  226.45\n17  1783.43  511.88  282.84  201.01  237.60   617.74   523.52  182.52\n18  3055.17  353.23  564.56  356.27  811.88   873.06  1082.82  420.81\n19  2033.87  300.82  338.65  157.78  329.06   621.74   587.02  218.27\n20  2057.86  186.44  202.72  171.79  329.65   477.17   312.93  279.19\n21  2303.29  589.99  516.21  236.55  403.92   730.05   438.41  225.80\n22  1974.28  507.76  344.79  203.21  240.24   575.10   430.36  223.46\n23  1673.82  437.75  461.61  153.32  254.66   445.59   346.11  191.48\n24  2194.25  537.01  369.07  249.54  290.84   561.91   407.70  330.95\n25  2646.61  839.70  204.44  209.11  379.30   371.04   269.59  389.33\n26  1472.95  390.89  447.95  259.51  230.61   490.90   469.10  191.34\n27  1525.57  472.98  328.90  219.86  206.65   449.69   249.66  228.19\n28  1654.69  437.77  258.78  303.00  244.93   479.53   288.56  236.51\n29  1375.46  480.89  273.84  317.32  251.08   424.75   228.73  195.93\n30  1608.82  536.05  432.46  235.82  250.28   541.30   344.85  214.40",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>1</th>\n      <th>2</th>\n      <th>3</th>\n      <th>4</th>\n      <th>5</th>\n      <th>6</th>\n      <th>7</th>\n      <th>8</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2959.19</td>\n      <td>730.79</td>\n      <td>749.41</td>\n      <td>513.34</td>\n      <td>467.87</td>\n      <td>1141.82</td>\n      <td>478.42</td>\n      <td>457.64</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2459.77</td>\n      <td>495.47</td>\n      <td>697.33</td>\n      <td>302.87</td>\n      <td>284.19</td>\n      <td>735.97</td>\n      <td>570.84</td>\n      <td>305.08</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1495.63</td>\n      <td>515.90</td>\n      <td>362.37</td>\n      <td>285.32</td>\n      <td>272.95</td>\n      <td>540.58</td>\n      <td>364.91</td>\n      <td>188.63</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1406.33</td>\n      <td>477.77</td>\n      <td>290.15</td>\n      <td>208.57</td>\n      <td>201.50</td>\n      <td>414.72</td>\n      <td>281.84</td>\n      <td>212.10</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1303.97</td>\n      <td>524.29</td>\n      <td>254.83</td>\n      <td>192.17</td>\n      <td>249.81</td>\n      <td>463.09</td>\n      <td>287.87</td>\n      <td>192.96</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>1730.84</td>\n      <td>553.90</td>\n      <td>246.91</td>\n      <td>279.81</td>\n      <td>239.18</td>\n      <td>445.20</td>\n      <td>330.24</td>\n      <td>163.86</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>1561.86</td>\n      <td>492.42</td>\n      <td>200.49</td>\n      <td>218.36</td>\n      <td>220.69</td>\n      <td>459.62</td>\n      <td>360.48</td>\n      <td>147.76</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>1410.11</td>\n      <td>510.71</td>\n      <td>211.88</td>\n      <td>277.11</td>\n      <td>224.65</td>\n      <td>376.82</td>\n      <td>317.61</td>\n      <td>152.85</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>3712.31</td>\n      <td>550.74</td>\n      <td>893.37</td>\n      <td>346.93</td>\n      <td>527.00</td>\n      <td>1034.98</td>\n      <td>720.33</td>\n      <td>462.03</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>2207.58</td>\n      <td>449.37</td>\n      <td>572.40</td>\n      <td>211.92</td>\n      <td>302.09</td>\n      <td>585.23</td>\n      <td>429.77</td>\n      <td>252.54</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>2629.16</td>\n      <td>557.32</td>\n      <td>689.73</td>\n      <td>435.69</td>\n      <td>514.66</td>\n      <td>795.87</td>\n      <td>575.76</td>\n      <td>323.36</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>1844.78</td>\n      <td>430.29</td>\n      <td>271.28</td>\n      <td>126.33</td>\n      <td>250.56</td>\n      <td>513.18</td>\n      <td>314.00</td>\n      <td>151.39</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>2709.46</td>\n      <td>428.11</td>\n      <td>334.12</td>\n      <td>160.77</td>\n      <td>405.14</td>\n      <td>461.67</td>\n      <td>535.13</td>\n      <td>232.29</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>1563.78</td>\n      <td>303.65</td>\n      <td>233.81</td>\n      <td>107.90</td>\n      <td>209.70</td>\n      <td>393.99</td>\n      <td>509.39</td>\n      <td>160.12</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>1675.75</td>\n      <td>613.32</td>\n      <td>550.71</td>\n      <td>219.79</td>\n      <td>272.59</td>\n      <td>599.43</td>\n      <td>371.62</td>\n      <td>211.84</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>1427.65</td>\n      <td>431.79</td>\n      <td>288.55</td>\n      <td>208.14</td>\n      <td>217.00</td>\n      <td>337.76</td>\n      <td>421.31</td>\n      <td>165.32</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>1942.23</td>\n      <td>512.27</td>\n      <td>401.39</td>\n      <td>206.06</td>\n      <td>321.29</td>\n      <td>697.22</td>\n      <td>492.60</td>\n      <td>226.45</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>1783.43</td>\n      <td>511.88</td>\n      <td>282.84</td>\n      <td>201.01</td>\n      <td>237.60</td>\n      <td>617.74</td>\n      <td>523.52</td>\n      <td>182.52</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>3055.17</td>\n      <td>353.23</td>\n      <td>564.56</td>\n      <td>356.27</td>\n      <td>811.88</td>\n      <td>873.06</td>\n      <td>1082.82</td>\n      <td>420.81</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>2033.87</td>\n      <td>300.82</td>\n      <td>338.65</td>\n      <td>157.78</td>\n      <td>329.06</td>\n      <td>621.74</td>\n      <td>587.02</td>\n      <td>218.27</td>\n    </tr>\n    <tr>\n      <th>20</th>\n      <td>2057.86</td>\n      <td>186.44</td>\n      <td>202.72</td>\n      <td>171.79</td>\n      <td>329.65</td>\n      <td>477.17</td>\n      <td>312.93</td>\n      <td>279.19</td>\n    </tr>\n    <tr>\n      <th>21</th>\n      <td>2303.29</td>\n      <td>589.99</td>\n      <td>516.21</td>\n      <td>236.55</td>\n      <td>403.92</td>\n      <td>730.05</td>\n      <td>438.41</td>\n      <td>225.80</td>\n    </tr>\n    <tr>\n      <th>22</th>\n      <td>1974.28</td>\n      <td>507.76</td>\n      <td>344.79</td>\n      <td>203.21</td>\n      <td>240.24</td>\n      <td>575.10</td>\n      <td>430.36</td>\n      <td>223.46</td>\n    </tr>\n    <tr>\n      <th>23</th>\n      <td>1673.82</td>\n      <td>437.75</td>\n      <td>461.61</td>\n      <td>153.32</td>\n      <td>254.66</td>\n      <td>445.59</td>\n      <td>346.11</td>\n      <td>191.48</td>\n    </tr>\n    <tr>\n      <th>24</th>\n      <td>2194.25</td>\n      <td>537.01</td>\n      <td>369.07</td>\n      <td>249.54</td>\n      <td>290.84</td>\n      <td>561.91</td>\n      <td>407.70</td>\n      <td>330.95</td>\n    </tr>\n    <tr>\n      <th>25</th>\n      <td>2646.61</td>\n      <td>839.70</td>\n      <td>204.44</td>\n      <td>209.11</td>\n      <td>379.30</td>\n      <td>371.04</td>\n      <td>269.59</td>\n      <td>389.33</td>\n    </tr>\n    <tr>\n      <th>26</th>\n      <td>1472.95</td>\n      <td>390.89</td>\n      <td>447.95</td>\n      <td>259.51</td>\n      <td>230.61</td>\n      <td>490.90</td>\n      <td>469.10</td>\n      <td>191.34</td>\n    </tr>\n    <tr>\n      <th>27</th>\n      <td>1525.57</td>\n      <td>472.98</td>\n      <td>328.90</td>\n      <td>219.86</td>\n      <td>206.65</td>\n      <td>449.69</td>\n      <td>249.66</td>\n      <td>228.19</td>\n    </tr>\n    <tr>\n      <th>28</th>\n      <td>1654.69</td>\n      <td>437.77</td>\n      <td>258.78</td>\n      <td>303.00</td>\n      <td>244.93</td>\n      <td>479.53</td>\n      <td>288.56</td>\n      <td>236.51</td>\n    </tr>\n    <tr>\n      <th>29</th>\n      <td>1375.46</td>\n      <td>480.89</td>\n      <td>273.84</td>\n      <td>317.32</td>\n      <td>251.08</td>\n      <td>424.75</td>\n      <td>228.73</td>\n      <td>195.93</td>\n    </tr>\n    <tr>\n      <th>30</th>\n      <td>1608.82</td>\n      <td>536.05</td>\n      <td>432.46</td>\n      <td>235.82</td>\n      <td>250.28</td>\n      <td>541.30</td>\n      <td>344.85</td>\n      <td>214.40</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "data=city.iloc[:,1:]\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "km=KMeans(n_clusters=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array([1, 2, 0, 0, 0, 3, 0, 0, 1, 2, 2, 3, 2, 0, 3, 0, 3, 3, 1, 3, 3, 2,\n       3, 3, 2, 2, 0, 0, 0, 0, 0])"
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "label=km.fit_predict(data)\n",
    "label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array([[1483.90166667,  464.5925    ,  298.6675    ,  236.09      ,\n         231.65416667,  447.72916667,  343.6925    ,  190.50916667],\n       [3242.22333333,  544.92      ,  735.78      ,  405.51333333,\n         602.25      , 1016.62      ,  760.52333333,  446.82666667],\n       [2450.01714286,  556.71      ,  483.32857143,  258.06428571,\n         368.59142857,  605.96285714,  461.02857143,  294.19285714],\n       [1857.42888889,  450.49222222,  344.54444444,  191.01111111,\n         274.98111111,  554.70777778,  412.04444444,  205.38444444]])"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "km.cluster_centers_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "expenses=np.sum(km.cluster_centers_,axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array([3696.83666667, 7754.65666667, 5477.89571429, 4290.59444444])"
     },
     "metadata": {},
     "execution_count": 10
    }
   ],
   "source": [
    "expenses"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "CityCluster = [[],[],[],[]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[['河北', '山西', '内蒙古', '吉林', '黑龙江', '江西', '河南', '陕西', '甘肃', '青海', '宁夏', '新疆'],\n ['北京', '上海', '广东'],\n ['天津', '江苏', '浙江', '福建', '重庆', '云南', '西藏'],\n ['辽宁', '安徽', '山东', '湖南', '湖北', '广西', '海南', '四川', '贵州']]"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "for i in range(len(cityName)):\n",
    "    CityCluster[label[i]].append(cityName[i])\n",
    "CityCluster"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Expenses:3696.84\n['河北', '山西', '内蒙古', '吉林', '黑龙江', '江西', '河南', '陕西', '甘肃', '青海', '宁夏', '新疆']\nExpenses:7754.66\n['北京', '上海', '广东']\nExpenses:5477.90\n['天津', '江苏', '浙江', '福建', '重庆', '云南', '西藏']\nExpenses:4290.59\n['辽宁', '安徽', '山东', '湖南', '湖北', '广西', '海南', '四川', '贵州']\n"
    }
   ],
   "source": [
    "for i in range(len(CityCluster)):\n",
    "    print('Expenses:%.2f'%expenses[i])\n",
    "    print(CityCluster[i])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 学生开始上网时间分布（DBSCAN）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "                                   0                1             2   \\\n0    2c929293466b97a6014754607e457d68       U201215025  A417314EEA7B   \n1    2c929293466b97a60147546099a57d81       U201116197  F0DEF1C78366   \n2    2c929293466b97a60147546099fa7d86       M201373803  88539523E88D   \n3    2c929293466b97a6014754609a137d88       M201370611  F0DEF167324F   \n4    2c929293466b97a601475460ab577d99       U201112081  B888E3813D3C   \n..                                ...              ...           ...   \n284  2c929293466b97a601475645b36d4b85       M201372774  68DFDD6703AB   \n285  2c929293466b97a60147564531de4abf       D201377117  041BBA75CF7A   \n286  2c929293466b97a6014756454e814ae5       U201013575  68DFDD27E77D   \n287  2c929293466b97a60147564551ba4aea  422123640321732  3CDFBD175878   \n288  2c929293466b97a601475645551d4af3       U201014641  002427FE3712   \n\n                 3                              4   \\\n0       10.12.49.26  2014-07-20 22:44:18.540000000   \n1      222.20.71.38  2014-07-20 12:14:21.380000000   \n2      10.12.59.230  2014-07-20 22:56:41.593000000   \n3    218.197.241.94  2014-07-20 23:19:30.930000000   \n4     218.197.229.5  2014-07-20 16:51:56.657000000   \n..              ...                            ...   \n284    10.10.194.32  2014-07-21 07:55:08.247000000   \n285    10.10.24.154  2014-07-21 07:47:43.700000000   \n286     10.12.63.48  2014-07-21 07:45:42.407000000   \n287    10.12.85.159  2014-07-21 08:05:49.327000000   \n288         0.0.0.0  2014-07-21 08:14:29.287000000   \n\n                                5      6   7          8        9         10  \n0    2014-07-20 23:10:16.540000000   1558  15  本科生动态IP模版  100元每半年  internet  \n1    2014-07-20 23:25:22.380000000  40261   1  本科生动态IP模版    20元每月  internet  \n2    2014-07-20 23:25:22.593000000   1721  15  研究生动态IP模版       计天  internet  \n3    2014-07-20 23:25:21.930000000    351   1  研究生动态IP模版    20元包月  internet  \n4    2014-07-20 23:24:40.657000000  23564   1  本科生动态IP模版     1元每天  internet  \n..                             ...    ...  ..        ...      ...       ...  \n284  2014-07-21 08:00:14.247000000    306  15  研究生动态IP模版    20元包月  internet  \n285  2014-07-21 08:14:41.700000000   1618  15  研究生动态IP模版       计天  internet  \n286  2014-07-21 08:14:48.407000000   1746  15  本科生动态IP模版     5元每周  internet  \n287  2014-07-21 08:14:49.273000000    540  15  本科生动态IP模版    20元每月  internet  \n288  2014-07-21 08:14:49.287000000     20   1  本科生动态IP模版  100元每半年  internet  \n\n[289 rows x 11 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n      <th>3</th>\n      <th>4</th>\n      <th>5</th>\n      <th>6</th>\n      <th>7</th>\n      <th>8</th>\n      <th>9</th>\n      <th>10</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2c929293466b97a6014754607e457d68</td>\n      <td>U201215025</td>\n      <td>A417314EEA7B</td>\n      <td>10.12.49.26</td>\n      <td>2014-07-20 22:44:18.540000000</td>\n      <td>2014-07-20 23:10:16.540000000</td>\n      <td>1558</td>\n      <td>15</td>\n      <td>本科生动态IP模版</td>\n      <td>100元每半年</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2c929293466b97a60147546099a57d81</td>\n      <td>U201116197</td>\n      <td>F0DEF1C78366</td>\n      <td>222.20.71.38</td>\n      <td>2014-07-20 12:14:21.380000000</td>\n      <td>2014-07-20 23:25:22.380000000</td>\n      <td>40261</td>\n      <td>1</td>\n      <td>本科生动态IP模版</td>\n      <td>20元每月</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2c929293466b97a60147546099fa7d86</td>\n      <td>M201373803</td>\n      <td>88539523E88D</td>\n      <td>10.12.59.230</td>\n      <td>2014-07-20 22:56:41.593000000</td>\n      <td>2014-07-20 23:25:22.593000000</td>\n      <td>1721</td>\n      <td>15</td>\n      <td>研究生动态IP模版</td>\n      <td>计天</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2c929293466b97a6014754609a137d88</td>\n      <td>M201370611</td>\n      <td>F0DEF167324F</td>\n      <td>218.197.241.94</td>\n      <td>2014-07-20 23:19:30.930000000</td>\n      <td>2014-07-20 23:25:21.930000000</td>\n      <td>351</td>\n      <td>1</td>\n      <td>研究生动态IP模版</td>\n      <td>20元包月</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2c929293466b97a601475460ab577d99</td>\n      <td>U201112081</td>\n      <td>B888E3813D3C</td>\n      <td>218.197.229.5</td>\n      <td>2014-07-20 16:51:56.657000000</td>\n      <td>2014-07-20 23:24:40.657000000</td>\n      <td>23564</td>\n      <td>1</td>\n      <td>本科生动态IP模版</td>\n      <td>1元每天</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>284</th>\n      <td>2c929293466b97a601475645b36d4b85</td>\n      <td>M201372774</td>\n      <td>68DFDD6703AB</td>\n      <td>10.10.194.32</td>\n      <td>2014-07-21 07:55:08.247000000</td>\n      <td>2014-07-21 08:00:14.247000000</td>\n      <td>306</td>\n      <td>15</td>\n      <td>研究生动态IP模版</td>\n      <td>20元包月</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>285</th>\n      <td>2c929293466b97a60147564531de4abf</td>\n      <td>D201377117</td>\n      <td>041BBA75CF7A</td>\n      <td>10.10.24.154</td>\n      <td>2014-07-21 07:47:43.700000000</td>\n      <td>2014-07-21 08:14:41.700000000</td>\n      <td>1618</td>\n      <td>15</td>\n      <td>研究生动态IP模版</td>\n      <td>计天</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>286</th>\n      <td>2c929293466b97a6014756454e814ae5</td>\n      <td>U201013575</td>\n      <td>68DFDD27E77D</td>\n      <td>10.12.63.48</td>\n      <td>2014-07-21 07:45:42.407000000</td>\n      <td>2014-07-21 08:14:48.407000000</td>\n      <td>1746</td>\n      <td>15</td>\n      <td>本科生动态IP模版</td>\n      <td>5元每周</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>287</th>\n      <td>2c929293466b97a60147564551ba4aea</td>\n      <td>422123640321732</td>\n      <td>3CDFBD175878</td>\n      <td>10.12.85.159</td>\n      <td>2014-07-21 08:05:49.327000000</td>\n      <td>2014-07-21 08:14:49.273000000</td>\n      <td>540</td>\n      <td>15</td>\n      <td>本科生动态IP模版</td>\n      <td>20元每月</td>\n      <td>internet</td>\n    </tr>\n    <tr>\n      <th>288</th>\n      <td>2c929293466b97a601475645551d4af3</td>\n      <td>U201014641</td>\n      <td>002427FE3712</td>\n      <td>0.0.0.0</td>\n      <td>2014-07-21 08:14:29.287000000</td>\n      <td>2014-07-21 08:14:49.287000000</td>\n      <td>20</td>\n      <td>1</td>\n      <td>本科生动态IP模版</td>\n      <td>100元每半年</td>\n      <td>internet</td>\n    </tr>\n  </tbody>\n</table>\n<p>289 rows × 11 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "data=pd.read_csv(\"./TestData.txt\",header=None)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "starttime=pd.to_datetime(data.iloc[:,4]).dt.hour"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "X=starttime.values.reshape(-1,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.cluster import DBSCAN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "db=DBSCAN(eps=0.01,min_samples=20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array([ 0, -1,  0,  1, -1,  1,  0,  1,  2, -1,  1,  0,  1,  1,  3, -1, -1,\n        3, -1,  1,  1, -1,  1,  3,  4, -1,  1,  1,  2,  0,  2,  2, -1,  0,\n        1,  0,  0,  0,  1,  3, -1,  0,  1,  1,  0,  0,  2, -1,  1,  3,  1,\n       -1,  3, -1,  3,  0,  1,  1,  2,  3,  3, -1, -1, -1,  0,  1,  2,  1,\n       -1,  3,  1,  1,  2,  3,  0,  1, -1,  2,  0,  0,  3,  2,  0,  1, -1,\n        1,  3, -1,  4,  2, -1, -1,  0, -1,  3, -1,  0,  2,  1, -1, -1,  2,\n        1,  1,  2,  0,  2,  1,  1,  3,  3,  0,  1,  2,  0,  1,  0, -1,  1,\n        1,  3, -1,  2,  1,  3,  1,  1,  1,  2, -1,  5, -1,  1,  3, -1,  0,\n        1,  0,  0,  1, -1, -1, -1,  2,  2,  0,  1,  1,  3,  0,  0,  0,  1,\n        4,  4, -1, -1, -1, -1,  4, -1,  4,  4, -1,  4, -1,  1,  2,  2,  3,\n        0,  1,  0, -1,  1,  0,  0,  1, -1, -1,  0,  2,  1,  0,  2, -1,  1,\n        1, -1, -1,  0,  1,  1, -1,  3,  1,  1, -1,  1,  1,  0,  0, -1,  0,\n       -1,  0,  0,  2, -1,  1, -1,  1,  0, -1,  2,  1,  3,  1,  1, -1,  1,\n        0,  0, -1,  0,  0,  3,  2,  0,  0,  5, -1,  3,  2, -1,  5,  4,  4,\n        4, -1,  5,  5, -1,  4,  0,  4,  4,  4,  5,  4,  4,  5,  5,  0,  5,\n        4, -1,  4,  5,  5,  5,  1,  5,  5,  0,  5,  4,  4, -1,  4,  4,  5,\n        4,  0,  5,  4, -1,  0,  5,  5,  5, -1,  4,  5,  5,  5,  5,  4,  4],\n      dtype=int64)"
     },
     "metadata": {},
     "execution_count": 17
    }
   ],
   "source": [
    "db.fit_predict(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels=db.fit_predict(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Noise ratio: 0.22145328719723184\n"
    }
   ],
   "source": [
    "print(\"Noise ratio:\",len(labels[labels==-1])/len(labels))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array([ 0, -1,  0,  1, -1,  1,  0,  1,  2, -1,  1,  0,  1,  1,  3, -1, -1,\n        3, -1,  1,  1, -1,  1,  3,  4, -1,  1,  1,  2,  0,  2,  2, -1,  0,\n        1,  0,  0,  0,  1,  3, -1,  0,  1,  1,  0,  0,  2, -1,  1,  3,  1,\n       -1,  3, -1,  3,  0,  1,  1,  2,  3,  3, -1, -1, -1,  0,  1,  2,  1,\n       -1,  3,  1,  1,  2,  3,  0,  1, -1,  2,  0,  0,  3,  2,  0,  1, -1,\n        1,  3, -1,  4,  2, -1, -1,  0, -1,  3, -1,  0,  2,  1, -1, -1,  2,\n        1,  1,  2,  0,  2,  1,  1,  3,  3,  0,  1,  2,  0,  1,  0, -1,  1,\n        1,  3, -1,  2,  1,  3,  1,  1,  1,  2, -1,  5, -1,  1,  3, -1,  0,\n        1,  0,  0,  1, -1, -1, -1,  2,  2,  0,  1,  1,  3,  0,  0,  0,  1,\n        4,  4, -1, -1, -1, -1,  4, -1,  4,  4, -1,  4, -1,  1,  2,  2,  3,\n        0,  1,  0, -1,  1,  0,  0,  1, -1, -1,  0,  2,  1,  0,  2, -1,  1,\n        1, -1, -1,  0,  1,  1, -1,  3,  1,  1, -1,  1,  1,  0,  0, -1,  0,\n       -1,  0,  0,  2, -1,  1, -1,  1,  0, -1,  2,  1,  3,  1,  1, -1,  1,\n        0,  0, -1,  0,  0,  3,  2,  0,  0,  5, -1,  3,  2, -1,  5,  4,  4,\n        4, -1,  5,  5, -1,  4,  0,  4,  4,  4,  5,  4,  4,  5,  5,  0,  5,\n        4, -1,  4,  5,  5,  5,  1,  5,  5,  0,  5,  4,  4, -1,  4,  4,  5,\n        4,  0,  5,  4, -1,  0,  5,  5,  5, -1,  4,  5,  5,  5,  5,  4,  4],\n      dtype=int64)"
     },
     "metadata": {},
     "execution_count": 20
    }
   ],
   "source": [
    "labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_clusters_=len(set(labels))-(1 if -1 in labels else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "6"
     },
     "metadata": {},
     "execution_count": 26
    }
   ],
   "source": [
    "n_clusters_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "0.7104124919280866"
     },
     "metadata": {},
     "execution_count": 31
    }
   ],
   "source": [
    "metrics.silhouette_score(X,labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Cluster  0 :\n[22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22]\nCluster  1 :\n[23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23]\nCluster  2 :\n[20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\nCluster  3 :\n[21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21]\nCluster  4 :\n[8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]\nCluster  5 :\n[7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]\n"
    }
   ],
   "source": [
    "for i in range(n_clusters_):\n",
    "    print(\"Cluster \",i,':')\n",
    "    print(list(X[labels==i].flatten()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(array([ 1.,  0.,  1.,  0.,  0.,  2.,  2., 24., 28.,  3.,  8.,  4.,  5.,\n         4.,  4.,  5.,  7.,  3.,  8.,  7., 28., 25., 55., 65.]),\n array([ 0.        ,  0.95833333,  1.91666667,  2.875     ,  3.83333333,\n         4.79166667,  5.75      ,  6.70833333,  7.66666667,  8.625     ,\n         9.58333333, 10.54166667, 11.5       , 12.45833333, 13.41666667,\n        14.375     , 15.33333333, 16.29166667, 17.25      , 18.20833333,\n        19.16666667, 20.125     , 21.08333333, 22.04166667, 23.        ]),\n <a list of 24 Patch objects>)"
     },
     "metadata": {},
     "execution_count": 36
    },
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\r\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n<!-- Created with matplotlib (https://matplotlib.org/) -->\r\n<svg height=\"248.518125pt\" version=\"1.1\" viewBox=\"0 0 368.925 248.518125\" width=\"368.925pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n <defs>\r\n  <style type=\"text/css\">\r\n*{stroke-linecap:butt;stroke-linejoin:round;}\r\n  </style>\r\n </defs>\r\n <g id=\"figure_1\">\r\n  <g id=\"patch_1\">\r\n   <path d=\"M -0 248.518125 \r\nL 368.925 248.518125 \r\nL 368.925 0 \r\nL -0 0 \r\nz\r\n\" style=\"fill:none;\"/>\r\n  </g>\r\n  <g id=\"axes_1\">\r\n   <g id=\"patch_2\">\r\n    <path d=\"M 26.925 224.64 \r\nL 361.725 224.64 \r\nL 361.725 7.2 \r\nL 26.925 7.2 \r\nz\r\n\" style=\"fill:#ffffff;\"/>\r\n   </g>\r\n   <g id=\"patch_3\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 42.143182 224.64 \r\nL 54.825 224.64 \r\nL 54.825 221.454066 \r\nL 42.143182 221.454066 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_4\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 54.825 224.64 \r\nL 67.506818 224.64 \r\nL 67.506818 224.64 \r\nL 54.825 224.64 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_5\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 67.506818 224.64 \r\nL 80.188636 224.64 \r\nL 80.188636 221.454066 \r\nL 67.506818 221.454066 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_6\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 80.188636 224.64 \r\nL 92.870455 224.64 \r\nL 92.870455 224.64 \r\nL 80.188636 224.64 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_7\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 92.870455 224.64 \r\nL 105.552273 224.64 \r\nL 105.552273 224.64 \r\nL 92.870455 224.64 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_8\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 105.552273 224.64 \r\nL 118.234091 224.64 \r\nL 118.234091 218.268132 \r\nL 105.552273 218.268132 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_9\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 118.234091 224.64 \r\nL 130.915909 224.64 \r\nL 130.915909 218.268132 \r\nL 118.234091 218.268132 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_10\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 130.915909 224.64 \r\nL 143.597727 224.64 \r\nL 143.597727 148.177582 \r\nL 130.915909 148.177582 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_11\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 143.597727 224.64 \r\nL 156.279545 224.64 \r\nL 156.279545 135.433846 \r\nL 143.597727 135.433846 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_12\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 156.279545 224.64 \r\nL 168.961364 224.64 \r\nL 168.961364 215.082198 \r\nL 156.279545 215.082198 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_13\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 168.961364 224.64 \r\nL 181.643182 224.64 \r\nL 181.643182 199.152527 \r\nL 168.961364 199.152527 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_14\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 181.643182 224.64 \r\nL 194.325 224.64 \r\nL 194.325 211.896264 \r\nL 181.643182 211.896264 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_15\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 194.325 224.64 \r\nL 207.006818 224.64 \r\nL 207.006818 208.71033 \r\nL 194.325 208.71033 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_16\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 207.006818 224.64 \r\nL 219.688636 224.64 \r\nL 219.688636 211.896264 \r\nL 207.006818 211.896264 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_17\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 219.688636 224.64 \r\nL 232.370455 224.64 \r\nL 232.370455 211.896264 \r\nL 219.688636 211.896264 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_18\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 232.370455 224.64 \r\nL 245.052273 224.64 \r\nL 245.052273 208.71033 \r\nL 232.370455 208.71033 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_19\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 245.052273 224.64 \r\nL 257.734091 224.64 \r\nL 257.734091 202.338462 \r\nL 245.052273 202.338462 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_20\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 257.734091 224.64 \r\nL 270.415909 224.64 \r\nL 270.415909 215.082198 \r\nL 257.734091 215.082198 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_21\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 270.415909 224.64 \r\nL 283.097727 224.64 \r\nL 283.097727 199.152527 \r\nL 270.415909 199.152527 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_22\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 283.097727 224.64 \r\nL 295.779545 224.64 \r\nL 295.779545 202.338462 \r\nL 283.097727 202.338462 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_23\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 295.779545 224.64 \r\nL 308.461364 224.64 \r\nL 308.461364 135.433846 \r\nL 295.779545 135.433846 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_24\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 308.461364 224.64 \r\nL 321.143182 224.64 \r\nL 321.143182 144.991648 \r\nL 308.461364 144.991648 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_25\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 321.143182 224.64 \r\nL 333.825 224.64 \r\nL 333.825 49.413626 \r\nL 321.143182 49.413626 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_26\">\r\n    <path clip-path=\"url(#p77d752f20a)\" d=\"M 333.825 224.64 \r\nL 346.506818 224.64 \r\nL 346.506818 17.554286 \r\nL 333.825 17.554286 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"matplotlib.axis_1\">\r\n    <g id=\"xtick_1\">\r\n     <g id=\"line2d_1\">\r\n      <defs>\r\n       <path d=\"M 0 0 \r\nL 0 3.5 \r\n\" id=\"m151075fdd9\" style=\"stroke:#000000;stroke-width:0.8;\"/>\r\n      </defs>\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"42.143182\" xlink:href=\"#m151075fdd9\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_1\">\r\n      <!-- 0 -->\r\n      <defs>\r\n       <path d=\"M 31.78125 66.40625 \r\nQ 24.171875 66.40625 20.328125 58.90625 \r\nQ 16.5 51.421875 16.5 36.375 \r\nQ 16.5 21.390625 20.328125 13.890625 \r\nQ 24.171875 6.390625 31.78125 6.390625 \r\nQ 39.453125 6.390625 43.28125 13.890625 \r\nQ 47.125 21.390625 47.125 36.375 \r\nQ 47.125 51.421875 43.28125 58.90625 \r\nQ 39.453125 66.40625 31.78125 66.40625 \r\nz\r\nM 31.78125 74.21875 \r\nQ 44.046875 74.21875 50.515625 64.515625 \r\nQ 56.984375 54.828125 56.984375 36.375 \r\nQ 56.984375 17.96875 50.515625 8.265625 \r\nQ 44.046875 -1.421875 31.78125 -1.421875 \r\nQ 19.53125 -1.421875 13.0625 8.265625 \r\nQ 6.59375 17.96875 6.59375 36.375 \r\nQ 6.59375 54.828125 13.0625 64.515625 \r\nQ 19.53125 74.21875 31.78125 74.21875 \r\nz\r\n\" id=\"DejaVuSans-48\"/>\r\n      </defs>\r\n      <g transform=\"translate(38.961932 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_2\">\r\n     <g id=\"line2d_2\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"108.30919\" xlink:href=\"#m151075fdd9\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_2\">\r\n      <!-- 5 -->\r\n      <defs>\r\n       <path d=\"M 10.796875 72.90625 \r\nL 49.515625 72.90625 \r\nL 49.515625 64.59375 \r\nL 19.828125 64.59375 \r\nL 19.828125 46.734375 \r\nQ 21.96875 47.46875 24.109375 47.828125 \r\nQ 26.265625 48.1875 28.421875 48.1875 \r\nQ 40.625 48.1875 47.75 41.5 \r\nQ 54.890625 34.8125 54.890625 23.390625 \r\nQ 54.890625 11.625 47.5625 5.09375 \r\nQ 40.234375 -1.421875 26.90625 -1.421875 \r\nQ 22.3125 -1.421875 17.546875 -0.640625 \r\nQ 12.796875 0.140625 7.71875 1.703125 \r\nL 7.71875 11.625 \r\nQ 12.109375 9.234375 16.796875 8.0625 \r\nQ 21.484375 6.890625 26.703125 6.890625 \r\nQ 35.15625 6.890625 40.078125 11.328125 \r\nQ 45.015625 15.765625 45.015625 23.390625 \r\nQ 45.015625 31 40.078125 35.4375 \r\nQ 35.15625 39.890625 26.703125 39.890625 \r\nQ 22.75 39.890625 18.8125 39.015625 \r\nQ 14.890625 38.140625 10.796875 36.28125 \r\nz\r\n\" id=\"DejaVuSans-53\"/>\r\n      </defs>\r\n      <g transform=\"translate(105.12794 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-53\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_3\">\r\n     <g id=\"line2d_3\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"174.475198\" xlink:href=\"#m151075fdd9\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_3\">\r\n      <!-- 10 -->\r\n      <defs>\r\n       <path d=\"M 12.40625 8.296875 \r\nL 28.515625 8.296875 \r\nL 28.515625 63.921875 \r\nL 10.984375 60.40625 \r\nL 10.984375 69.390625 \r\nL 28.421875 72.90625 \r\nL 38.28125 72.90625 \r\nL 38.28125 8.296875 \r\nL 54.390625 8.296875 \r\nL 54.390625 0 \r\nL 12.40625 0 \r\nz\r\n\" id=\"DejaVuSans-49\"/>\r\n      </defs>\r\n      <g transform=\"translate(168.112698 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-49\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_4\">\r\n     <g id=\"line2d_4\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"240.641206\" xlink:href=\"#m151075fdd9\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_4\">\r\n      <!-- 15 -->\r\n      <g transform=\"translate(234.278706 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-49\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-53\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_5\">\r\n     <g id=\"line2d_5\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"306.807213\" xlink:href=\"#m151075fdd9\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_5\">\r\n      <!-- 20 -->\r\n      <defs>\r\n       <path d=\"M 19.1875 8.296875 \r\nL 53.609375 8.296875 \r\nL 53.609375 0 \r\nL 7.328125 0 \r\nL 7.328125 8.296875 \r\nQ 12.9375 14.109375 22.625 23.890625 \r\nQ 32.328125 33.6875 34.8125 36.53125 \r\nQ 39.546875 41.84375 41.421875 45.53125 \r\nQ 43.3125 49.21875 43.3125 52.78125 \r\nQ 43.3125 58.59375 39.234375 62.25 \r\nQ 35.15625 65.921875 28.609375 65.921875 \r\nQ 23.96875 65.921875 18.8125 64.3125 \r\nQ 13.671875 62.703125 7.8125 59.421875 \r\nL 7.8125 69.390625 \r\nQ 13.765625 71.78125 18.9375 73 \r\nQ 24.125 74.21875 28.421875 74.21875 \r\nQ 39.75 74.21875 46.484375 68.546875 \r\nQ 53.21875 62.890625 53.21875 53.421875 \r\nQ 53.21875 48.921875 51.53125 44.890625 \r\nQ 49.859375 40.875 45.40625 35.40625 \r\nQ 44.1875 33.984375 37.640625 27.21875 \r\nQ 31.109375 20.453125 19.1875 8.296875 \r\nz\r\n\" id=\"DejaVuSans-50\"/>\r\n      </defs>\r\n      <g transform=\"translate(300.444713 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-50\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n   </g>\r\n   <g id=\"matplotlib.axis_2\">\r\n    <g id=\"ytick_1\">\r\n     <g id=\"line2d_6\">\r\n      <defs>\r\n       <path d=\"M 0 0 \r\nL -3.5 0 \r\n\" id=\"m31f6763623\" style=\"stroke:#000000;stroke-width:0.8;\"/>\r\n      </defs>\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"26.925\" xlink:href=\"#m31f6763623\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_6\">\r\n      <!-- 0 -->\r\n      <g transform=\"translate(13.5625 228.439219)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_2\">\r\n     <g id=\"line2d_7\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"26.925\" xlink:href=\"#m31f6763623\" y=\"192.780659\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_7\">\r\n      <!-- 10 -->\r\n      <g transform=\"translate(7.2 196.579878)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-49\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_3\">\r\n     <g id=\"line2d_8\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"26.925\" xlink:href=\"#m31f6763623\" y=\"160.921319\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_8\">\r\n      <!-- 20 -->\r\n      <g transform=\"translate(7.2 164.720537)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-50\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_4\">\r\n     <g id=\"line2d_9\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"26.925\" xlink:href=\"#m31f6763623\" y=\"129.061978\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_9\">\r\n      <!-- 30 -->\r\n      <defs>\r\n       <path d=\"M 40.578125 39.3125 \r\nQ 47.65625 37.796875 51.625 33 \r\nQ 55.609375 28.21875 55.609375 21.1875 \r\nQ 55.609375 10.40625 48.1875 4.484375 \r\nQ 40.765625 -1.421875 27.09375 -1.421875 \r\nQ 22.515625 -1.421875 17.65625 -0.515625 \r\nQ 12.796875 0.390625 7.625 2.203125 \r\nL 7.625 11.71875 \r\nQ 11.71875 9.328125 16.59375 8.109375 \r\nQ 21.484375 6.890625 26.8125 6.890625 \r\nQ 36.078125 6.890625 40.9375 10.546875 \r\nQ 45.796875 14.203125 45.796875 21.1875 \r\nQ 45.796875 27.640625 41.28125 31.265625 \r\nQ 36.765625 34.90625 28.71875 34.90625 \r\nL 20.21875 34.90625 \r\nL 20.21875 43.015625 \r\nL 29.109375 43.015625 \r\nQ 36.375 43.015625 40.234375 45.921875 \r\nQ 44.09375 48.828125 44.09375 54.296875 \r\nQ 44.09375 59.90625 40.109375 62.90625 \r\nQ 36.140625 65.921875 28.71875 65.921875 \r\nQ 24.65625 65.921875 20.015625 65.03125 \r\nQ 15.375 64.15625 9.8125 62.3125 \r\nL 9.8125 71.09375 \r\nQ 15.4375 72.65625 20.34375 73.4375 \r\nQ 25.25 74.21875 29.59375 74.21875 \r\nQ 40.828125 74.21875 47.359375 69.109375 \r\nQ 53.90625 64.015625 53.90625 55.328125 \r\nQ 53.90625 49.265625 50.4375 45.09375 \r\nQ 46.96875 40.921875 40.578125 39.3125 \r\nz\r\n\" id=\"DejaVuSans-51\"/>\r\n      </defs>\r\n      <g transform=\"translate(7.2 132.861197)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-51\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_5\">\r\n     <g id=\"line2d_10\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"26.925\" xlink:href=\"#m31f6763623\" y=\"97.202637\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_10\">\r\n      <!-- 40 -->\r\n      <defs>\r\n       <path d=\"M 37.796875 64.3125 \r\nL 12.890625 25.390625 \r\nL 37.796875 25.390625 \r\nz\r\nM 35.203125 72.90625 \r\nL 47.609375 72.90625 \r\nL 47.609375 25.390625 \r\nL 58.015625 25.390625 \r\nL 58.015625 17.1875 \r\nL 47.609375 17.1875 \r\nL 47.609375 0 \r\nL 37.796875 0 \r\nL 37.796875 17.1875 \r\nL 4.890625 17.1875 \r\nL 4.890625 26.703125 \r\nz\r\n\" id=\"DejaVuSans-52\"/>\r\n      </defs>\r\n      <g transform=\"translate(7.2 101.001856)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-52\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_6\">\r\n     <g id=\"line2d_11\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"26.925\" xlink:href=\"#m31f6763623\" y=\"65.343297\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_11\">\r\n      <!-- 50 -->\r\n      <g transform=\"translate(7.2 69.142515)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-53\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_7\">\r\n     <g id=\"line2d_12\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"26.925\" xlink:href=\"#m31f6763623\" y=\"33.483956\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_12\">\r\n      <!-- 60 -->\r\n      <defs>\r\n       <path d=\"M 33.015625 40.375 \r\nQ 26.375 40.375 22.484375 35.828125 \r\nQ 18.609375 31.296875 18.609375 23.390625 \r\nQ 18.609375 15.53125 22.484375 10.953125 \r\nQ 26.375 6.390625 33.015625 6.390625 \r\nQ 39.65625 6.390625 43.53125 10.953125 \r\nQ 47.40625 15.53125 47.40625 23.390625 \r\nQ 47.40625 31.296875 43.53125 35.828125 \r\nQ 39.65625 40.375 33.015625 40.375 \r\nz\r\nM 52.59375 71.296875 \r\nL 52.59375 62.3125 \r\nQ 48.875 64.0625 45.09375 64.984375 \r\nQ 41.3125 65.921875 37.59375 65.921875 \r\nQ 27.828125 65.921875 22.671875 59.328125 \r\nQ 17.53125 52.734375 16.796875 39.40625 \r\nQ 19.671875 43.65625 24.015625 45.921875 \r\nQ 28.375 48.1875 33.59375 48.1875 \r\nQ 44.578125 48.1875 50.953125 41.515625 \r\nQ 57.328125 34.859375 57.328125 23.390625 \r\nQ 57.328125 12.15625 50.6875 5.359375 \r\nQ 44.046875 -1.421875 33.015625 -1.421875 \r\nQ 20.359375 -1.421875 13.671875 8.265625 \r\nQ 6.984375 17.96875 6.984375 36.375 \r\nQ 6.984375 53.65625 15.1875 63.9375 \r\nQ 23.390625 74.21875 37.203125 74.21875 \r\nQ 40.921875 74.21875 44.703125 73.484375 \r\nQ 48.484375 72.75 52.59375 71.296875 \r\nz\r\n\" id=\"DejaVuSans-54\"/>\r\n      </defs>\r\n      <g transform=\"translate(7.2 37.283175)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#DejaVuSans-54\"/>\r\n       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n   </g>\r\n   <g id=\"patch_27\">\r\n    <path d=\"M 26.925 224.64 \r\nL 26.925 7.2 \r\n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n   </g>\r\n   <g id=\"patch_28\">\r\n    <path d=\"M 361.725 224.64 \r\nL 361.725 7.2 \r\n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n   </g>\r\n   <g id=\"patch_29\">\r\n    <path d=\"M 26.925 224.64 \r\nL 361.725 224.64 \r\n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n   </g>\r\n   <g id=\"patch_30\">\r\n    <path d=\"M 26.925 7.2 \r\nL 361.725 7.2 \r\n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n   </g>\r\n  </g>\r\n </g>\r\n <defs>\r\n  <clipPath id=\"p77d752f20a\">\r\n   <rect height=\"217.44\" width=\"334.8\" x=\"26.925\" y=\"7.2\"/>\r\n  </clipPath>\r\n </defs>\r\n</svg>\r\n",
      "image/png": "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\n"
     },
     "metadata": {
      "needs_background": "light"
     }
    }
   ],
   "source": [
    "plt.hist(X,bins=24)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import PIL.Image as image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "def loadData(filePath):\n",
    "    f=open(filePath,'rb')\n",
    "    data=[]\n",
    "    img=image.open(f)\n",
    "    m,n=img.size\n",
    "    for i in range(m):\n",
    "        for j in range(n):\n",
    "            x,y,z=img.getpixel((i,j))\n",
    "            data.append([x/256.0,y/256.0,z/256.0])\n",
    "    return np.mat(data),m,n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "imgData,row,col=loadData(\"./bull.jpg\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "km=KMeans(n_clusters=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels=km.fit_predict(imgData).reshape(row,col)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "pic_new=image.new('L',(row,col))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(row):\n",
    "    for j in range(col):\n",
    "        pic_new.putpixel((i,j),int(256/(labels[i,j]+1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "pic_new.save('./resultImg.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}